import CONST from './const'
const upperCase = val => {
  if (val) {
    return val.toString().toUpperCase()
  } else {
    return ''
  }
}

const formatAddress = deviceInfo => {
  let address = ''
  if (deviceInfo) {
    address += deviceInfo.province
      ? deviceInfo.province.cityNameZh
      : ''
    address += deviceInfo.city
      ? deviceInfo.city.cityNameZh
      : ''
    address += deviceInfo.district
      ? deviceInfo.district.cityNameZh
      : ''
    address += deviceInfo.address || ''
  }
  return address || '未配置'
}

const timeUnitText = timeUnitValue => {
  const timeUnit = CONST.TIME_UNIT.find(item => item.value === timeUnitValue)
  if (timeUnit) {
    return timeUnit.label
  } else {
    return ''
  }
}

export default {
  upperCase,
  formatAddress,
  timeUnitText
}
